home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Graphics Plus
/
Graphics Plus.iso
/
general
/
viewers
/
prev
/
prev.lha
/
symbol.c
< prev
next >
Wrap
C/C++ Source or Header
|
1991-01-29
|
898b
|
60 lines
#include <stdio.h>
#include <math.h>
#include "art.h"
/*
* findsym
*
* retrieve a symbol from a symbol tree
*/
symbol *
findsym(tree, s)
symbol *tree;
char *s;
{
int val;
if (tree != (symbol *)NULL) {
val = strcmp(tree->name, s);
if (val == 0)
return(tree);
if (val < 0)
return(findsym(tree->left, s));
else
return(findsym(tree->right, s));
}
return((symbol *)NULL);
}
/*
* insertsym
*
* insert a symbol into a symbol tree.
*/
symbol *
insertsym(tree, s)
symbol **tree;
char *s;
{
int val;
symbol *sym;
if (*tree != (symbol *)NULL) {
val = strcmp((*tree)->name, s);
if (val == 0)
return(*tree);
if (val < 0)
return(insertsym(&(*tree)->left, s));
else
return(insertsym(&(*tree)->right, s));
}
*tree = sym = (symbol *)smalloc(sizeof(symbol));
sym->name = s;
sym->left = (symbol *)NULL;
sym->right = (symbol *)NULL;
return(sym);
}